﻿using Guest_room.BLL;
using System;
using System.Windows.Forms;

namespace Guest_room.employee
{
    public partial class UpdateStayDaysForm : Form
    {
        public UpdateStayDaysForm(string roomNumber, int currentStayDays, string roomtime, int peoples)
        {
            InitializeComponent();
            textBox1.Text = currentStayDays.ToString();
            textBox2.Text = peoples.ToString();
            dateTimePicker1.Value = Convert.ToDateTime(roomtime);
            this.roomNumber = roomNumber;
        }
        string roomNumber;
        private void UpdateStayDaysForm_Load(object sender, EventArgs e)
        {

        }
        public class StayInfo
        {
            public int Days { get; set; }
            public int Number { get; set; }
            public DateTime CheckInTime { get; set; }
        }

        public StayInfo GetStayDays()
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("请输入入住天数！");
                return new StayInfo { Days = -1, Number = -1, CheckInTime = DateTime.MinValue };
            }
            else if (Convert.ToInt32(textBox1.Text) <= 0)
            {
                MessageBox.Show("入住天数必须大于0！");
                return new StayInfo { Days = -1, Number = -1, CheckInTime = DateTime.MinValue };
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("请输入入住人数！");
                return new StayInfo { Days = -1, Number = -1, CheckInTime = DateTime.MinValue };
            }
            else if (Convert.ToInt32(textBox2.Text) <= 0)
            {
                MessageBox.Show("入住人数必须大于0！");
                return new StayInfo { Days = -1, Number = -1, CheckInTime = DateTime.MinValue };
            }
            //else if (dateTimePicker1.Value < DateTime.Now)
            //{
            //    MessageBox.Show("入住时间必须大于当前时间！");
            //    return new StayInfo { Days = -1, Number = -1, CheckInTime = DateTime.MinValue };
            //}
            else
            {
                try
                {
                    //返回入住天数，入住人数，入住时间
                    return new StayInfo
                    {
                        Days = Convert.ToInt32(textBox1.Text),
                        Number = Convert.ToInt32(textBox2.Text),
                        CheckInTime = dateTimePicker1.Value
                    };
                }
                catch (Exception)
                {
                    MessageBox.Show("请输入正确的内容！");
                    return new StayInfo { Days = -1, Number = -1, CheckInTime = DateTime.MinValue };
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)//确定
        {
            DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)//删除
        {
            //删除入住信息
            //DB.GetCn();
            //string str = "delete from 用户购物车表 where 客房编号='" + roomNumber + "';update 客房档次表 set 空房数=空房数+1 where 档次编号 in (select 档次编号 from 客房基本信息表 where 客房编号='" + roomNumber + "');" +
            //        "update 客房基本信息表 SET 客房状态 = '空闲' WHERE 客房编号 = '" + roomNumber + "';";
            //DB.sqlEx(str);
            GuestRoomService guestRoomService = new GuestRoomService();
            string roomNumber = "123"; // 示例客房编号
            bool result = guestRoomService.DeleteCheckInInfo(roomNumber);
            if (result)
            {
                // 删除成功后的处理
                MessageBox.Show("删除成功！");
                DialogResult = DialogResult.OK;
                this.Close();
            }

            //MessageBox.Show("删除成功！");
            //DialogResult = DialogResult.OK;
            //this.Close();

        }
    }
}
